package com.xingkeduo.business.operation.controller.cms;

import com.alibaba.fastjson.JSON;
import com.xingkeduo.business.operation.controller.InitController;
import com.xingkeduo.business.operation.domain.ManagerDomain;
import com.xingkeduo.pojo.json.ManagerJson;
import com.xingkeduo.pojo.table.ManagerTable;
import com.xingkeduo.util.tool.ReturnUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static com.xingkeduo.tool.OperaConstants.CMS_URL_PREFIX;

@Slf4j
@RestController
@RequestMapping(CMS_URL_PREFIX + "/login")
public class LoginController extends InitController {

    @Autowired
    private ManagerDomain managerDomain;
    @RequestMapping(value = "/{urlParam:.+}", method = RequestMethod.GET)
    public String doLogin(@PathVariable String urlParam) {
         returnUtil= new ReturnUtil();
        try {

            ManagerTable managerTable = new ManagerTable();
            managerTable =  JSON.parseObject(urlParam,ManagerTable.class);
            log.info("登录接口请求参数:{}", JSON.toJSONString(managerTable));
            ManagerTable managerTable1 = managerDomain.getLongin(managerTable);
            log.info("登录接口返回值:{}", JSON.toJSONString(managerTable1));
            //return returnUtil.getSuccess(managerJson.toJson(userId));L
            return returnUtil.getSuccess(ManagerJson.toJson(managerTable1));
        } catch (Throwable throwable) {
            return dealException(throwable, returnUtil);
        }
    }

}
